package org.ssp.util;

import net.sf.json.JSONObject;

/*
 * 多客服工具类
 */
public class CustomerServiceUtil {
	public static final String KEFUINFO_URL="https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token=ACCESS_TOKEN";
	public static final String CREATEKEFU_URL="https://api.weixin.qq.com/customservice/kfaccount/add?access_token=ACCESS_TOKEN";

	//获取客服信息
	public static String getKefuInfo(String access_token){
	    String url=KEFUINFO_URL.replace("ACCESS_TOKEN", access_token);
	    String str=null;
	    try {
			str=CommonUtil.httpsRequest(url, "GET", null);//微信服务器返回的json值
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			
		return str;
	}
	//创建客服
	public static boolean CretaeKeFu(String access_token,String json){
		boolean result=false;
		String url=CREATEKEFU_URL.replace("ACCESS_TOKEN", access_token);
		String str=null;
		try {
			str=CommonUtil.httpsRequest(url, "POST", json);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		通过json-lib的API把json字符串转化成java对象
		JSONObject jsonObject=JSONObject.fromObject(str);
		if(null!=jsonObject){
			int errcode=jsonObject.getInt("errcode");
			String str1=jsonObject.getString("errmsg");
			
			if(errcode==0){
				result=true;
			}else{
				System.out.println("创建失败"+errcode+"\t"+str1);
			}
			
		}
		return result;
	}
}

